/**
 * 权限封装工具类
 * @author 邓志军
 * @since 2024年1月25日19:23:04
 */
import storage from "@/utils/localStorageUtils";
import { commonObject } from "@/variable/common.js";
import { getRouters as getUserRouters } from "@/api/login.js"
import store from '@/store'

// ================= token 相关 =========================
export function getToken() {
  return storage.get(commonObject.token)
}

export function setToken(token) {
  return storage.set(commonObject.token, token)
}

export function removeToken() {
  return storage.remove(commonObject.token)
}

// ================= 路由相关 =========================
export function getRouters() {
  return storage.get(commonObject.routers)
}

export function setRouterss(routers) {
  return storage.set(commonObject.routers, routers)
}

export function removeRouters() {
  return storage.remove(commonObject.routers)
}

// 刷新路由权限
export function refreshPermission() {
  getUserRouters().then(res => {
    store.commit('setRoutes', res.data)
    window.location.reload()
  })
}